import { _decorator, Component, Label } from 'cc';
const { ccclass, inspector, property } = _decorator;

import * as cc from "cc";
import { VMCenter } from '../../framework/vm/VMCenter';
import { userData } from '../../game/storage/UserData';
import { VMBaseAttr, VMEntity } from '../../framework/vm/VMEntity';
import { mvvm, VMCustom, VMNode } from '../../framework/vm/VMDecorator';
import { DemoVMSceneBase } from './DemoVMSceneBase';

@ccclass('DemoVMSprite')
// @mvvm()
export default class DemoVMSprite extends DemoVMSceneBase implements IMVVM{
    _vmTag: string;
    _vmEntitys: VMEntity[];


    @property(cc.Sprite)
    icon: cc.Sprite = null;

    @property(cc.Label)
    pathLabel: cc.Label = null;

    @property(cc.Button)
    btnChanage: cc.Button = null;

    @property(cc.Node)
    starGroup: cc.Node = null;


    data = {
        icon: "setting/setting3/spriteFrame",
        iconIdx: -1,
        icons: ["setting/setting1/spriteFrame","setting/setting2/spriteFrame","setting/setting3/spriteFrame",],
    }

    onLoad() {
    }
    start() {
        super.start();
    }

    onEnable(){
        VMCenter.add(this.data,this);

        VMCenter.Label(this,this.pathLabel,{ watchPath: "*.icon" });
        VMCenter.Sprite(this,this.icon,{ watchPath: "*.icon" });
        

        
        VMCenter.Sprite(this,this.starGroup,{ watchPath: "*.icon" ,controlChildren: true});


        VMCenter.ButtonClick(this,this.btnChanage,{
                watchPath: '*.icon', operation: (param) => {
                    this.data.iconIdx ++;
                    this.data.iconIdx %= this.data.icons.length;
                    return param.currentValue = this.data.icons[this.data.iconIdx];
                }
        });
        
    }
    onDisable(){
        VMCenter.remove(this);
    }

    onClickAddAtk() {
        userData.atk ++;
    }

    onClickMulAtk() {
        userData.atk --;
    }
}

